const {
  request
} = require("../../utils/index.js")
// pages/Recruicoop/Recruicoop.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    resultList: [],  //招聘合作列表数据
    Eliteshare: {
      isMy:'false',  //只看自己
      pageNum: 1,   //页数
      pageSize: 10,   //条数
      searchLabel: "",   //搜索标签
      searchName: "",   //名称查询
    },
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.onHide();
    
    this.init();
  },

  //招聘合作数据资料
  async init() {
    try {
      let that = this;
      let par = {
        url: "hw/portal/recruited/page?token=" + wx.getStorageSync('token'),
        method: "GET",
        data: that.data.Eliteshare,
        header: {
          "Content-Type": "application/json"
        }
      }
      let datainfo = await request(par);
      this.setData({
        resultList:datainfo.data
      })
    } catch (error) {
      console.log(error)
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */ 
  onHide: function () {

  },

  //名称查询
  result(e){
    this.setData({
      "Eliteshare.searchName":e.detail
    });
    this.init();
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let that=this;
    console.log(that.data.Eliteshare);
    that.setData({
      Eliteshare: {
        pageNum: 1,   //页数
        pageSize: 10,   //条数
        searchName: "",   //名称查询
        articlesLabel: "business"
      },
    })
    console.log(that.data.Eliteshare);
    that.init();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: async function () {
    wx.showNavigationBarLoading(); //显示加载
    //模拟加载  1秒
    let that = this;
    if(this.data.Eliteshare.pageNum>=this.data.resultList.lastPage){
      wx.showToast({
        title: '滑倒底了',
        icon:"none"
      })
      wx.hideNavigationBarLoading();  //停止加载
      return;
    }
    this.setData({
      "Eliteshare.pageNum":++this.data.Eliteshare.pageNum
    })
    let par = {
      url:"hw/portal/recruited/page?token=" + wx.getStorageSync('token'),
      method:"GET",
      data:that.data.Eliteshare,
      header: {
        "Content-Type": "application/json"
      },
    }
    let datainfo = await request(par);
    if(datainfo.data != undefined){
      let lao = that.data.resultList.list //将老数据存入
      if(datainfo.data.list){
        let list = [...lao,...datainfo.data.list]  //新老数据拼接
        that.setData({
          resultList:datainfo.data,  //重新赋值
          "resultList.list": list
        })
      }
    }else{
      // 滑倒底了
    }
    wx.hideNavigationBarLoading(); //停止加载
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})